/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 hujiang All Rights Reserved
// Name:        common_types.h
// Purpose:
// Author:      yfq
// Modified by:
// Created:     2014/1/3 14:08
// RCS-ID:
// Licence:
/////////////////////////////////////////////////////////////////////////////
#ifndef QB_COMMON_TYPES_H_
#define QB_COMMON_TYPES_H_
#include "core.h"
#include "typedefs.h"

#if defined(_MSC_VER)
// Disable "new behavior: elements of array will be default initialized"
// warning. Affects OverUseDetectorOptions.
#pragma warning(disable : 4351)
#endif

#if defined(QB_WIN)
// Compares two strings without regard to case.
#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
// Compares characters of two strings without regard to case.
#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
#else
#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
#endif

namespace qb {
class S_CORE_EXPORT InStream {
 public:
  virtual int Read(void *buf, int len) = 0;
  virtual int Rewind() { return -1; }
  virtual ~InStream() {}

 protected:
  InStream() {}
};

class S_CORE_EXPORT OutStream {
 public:
  virtual bool Write(const void *buf, int len) = 0;
  virtual int Rewind() { return -1; }
  virtual ~OutStream() {}

 protected:
  OutStream() {}
};

enum TraceModule {
  kTraceUndefined = 0,
  kTraceNetworkService = 0x0001,
  kTraceMessageSync = 0x0002,
  kTraceMessageKernel = 0x0003,
  kTraceClientKernel = 0x0004,
  kTraceFileModele = 0x0005,
  kTraceFileTransfer = 0x0006,
  kTraceUIIM = 0x0007,
  kTraceUtility = 0x0008,
  kTraceIMLogic = 0x0009,
  kTraceUserFace = 0x000b,
  kTraceDataCenter = 0x000c,
  kTraceUIResService = 0x000d,
  kTraceImageKernel = 0x000e,
  kTraceUIPPT = 0x0010,
  kTraceDataReport = 0x0011,
  kTraceNetworkRouting = 0x0012,
  kTraceUIASSIST = 0x0013,
  kTraceCommonHead = 0x0014,
  kTraceHttpModule = 0x0015,
  kTraceHttpKernel = 0x0016,
  kTraceCCore = 0x0017,
  kTraceUIChatFrame = 0x0018,
  kTraceUIFeatures = 0x0019,
  kTraceDBModule = 0x0020,
  kTraceUserHeadModule = 0x0021,
};

enum TraceLevel {
  kTraceNone = 0x0000,  // no trace
  kTraceStateInfo = 0x0001,
  kTraceWarning = 0x0002,
  kTraceError = 0x0004,
  kTraceCritical = 0x0008,
  kTraceApiCall = 0x0010,
  kTraceDefault = 0x00ff,

  kTraceModuleCall = 0x0020,
  kTraceMemory = 0x0100,  // memory info
  kTraceTimer = 0x0200,   // timing info
  kTraceStream = 0x0400,  // "continuous" stream of data

  // used for debug purposes
  kTraceDebug = 0x0800,  // for positioning problem
  kTraceInfo = 0x1000,   // debug info

  // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
  kTraceTerseInfo = 0x2000,

  kTraceAll = 0xffff
};

// External Trace API
class TraceCallback {
 public:
  virtual void Print(TraceLevel level, const char *message, int length) = 0;

 protected:
  virtual ~TraceCallback() {}
  TraceCallback() {}
};

#define LOGIN_CONNECT_TIME 10
#define LOGIN_VERIFY_TIMEOUT 10
#define LOGIN_AUTHORITY_TIMEOUT 20

// socket types
enum SocketType {
  kSocketUdp,
  kSocketTcp,
};

// connect status
enum ConnectStatus {
  kConnectTimeout,        // 连接超时
  kConnectConnected,      // 连接成功
  kConnectError,          // 网络错误
  kConnectConnectFailed,  // 连接失败
  kConnectReconnect,      // 重连（udp内部使用）
  kConnectSendError,      // 发送错误
  KConnectRecvError,      // 接收错误
};

// net status
enum NetStatus {
  eNetStatus_None,             // null
  eNetStatus_ConnectingLogin,  // 连接登录服务器
  eNetStatus_ConnectedLogin,   // 登录服务器连接成功
  eNetStatus_VerifyLogin,      // 验证服务器登录
  eNetStatus_ConnectingGW,     // 连接网关服务器
  eNetStatus_ConnectedGW,      // 网关服务器连接成功
  eNetStatus_VerifyGW,         // 验证服务器网关
  eNetStatus_Authority,        // 用户权限
  eNetStatus_Done,             // 登录结束
};

enum eNetErrorCode {
  eNetError_ConnectServerError = -1,    // 连接LoginServer发生错误
  eNetError_ConnectServerTimeout = -2,  // 连接LoginServer超时
  eNetError_CreateThreadFailed = -3,    // 创建线程失败
  eNetError_ReloginServer = -4,         // 重新登录
  eNetError_SendToServerFailed = -5,    // 发送数据到Server失败
  eNetError_RecvFromServerFailed = -6,  // 接收Server数据失败
  eNetError_DataParseError = -7,        // 数据解析错误
  eNetError_TaskTimeout = -8,           // 任务超时
};

}  // namespace qb

#endif  // QB_COMMON_TYPES_H_
